package routes

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"project/jwt-prac/controllers"
	"project/jwt-prac/middlewares"
)

func InitRoutes(r *gin.Engine) {
	r.GET("/test", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"status": "normal",
			"msg":    "test web interface",
		})
	})

	r.StaticFile("/smiley.gif", "resources/static/smiley.gif")
	r.StaticFile("/favicon.ico", "resources/static/favicon.ico")
	r.StaticFile("/index", "resources/templates/index.html")
	r.Static("static", "resources")

	r.StaticFile("/login", "resources/templates/login.html")
	r.POST("/login", controllers.LoginPost)
	r.StaticFile("/register", "resources/templates/register.html")
	r.POST("/register", controllers.RegisterPost)

	// jwt auth
	auth := r.Group("/secrets")
	auth.Use(middlewares.JWTAuth())
	{
		auth.GET("/test", func(c *gin.Context) {
			c.String(200, "Secrets tests")
		})
	}
}
